-
Notifications
You must be signed in to change notification settings - Fork 299
Conversation
I need a way to hint the block API which hash function to use and also, which version of CID, so that I can store blocks from different formats. This is also useful for Bitswap, since the Block API uses the BlockService and the BlockService is the gateway for Bitswap. Currently, in js-ipfs, I pass the block and the CID, which packs the information I need. @whyrusleeping I was checking the go-ipfs master branch to find how to hint the block API which hash algorithm, but noticed option isn't added.
I believe you have this in the 'programmatic' interface and are defaulting to sha2-256 on the CLI, is this right? Will you add this feature to the Block API? so that I can have the same interface in both js-ipfs and js-ipfs-api. Thank you :) |
9ed6eae
to
9a99d5a
Compare
@@ -2,7 +2,7 @@ | |||
"name": "ipfs-api", | |||
"version": "9.0.0", | |||
"description": "A client library for the IPFS HTTP API. Follows interface-ipfs-core spec", | |||
"main": "lib/index.js", | |||
"main": "src/index.js", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: remove before merge
|
||
module.exports = (send) => { | ||
return { | ||
get: promisify((args, opts, callback) => { | ||
// TODO this needs to be adjusted with the new go-ipfs | ||
// http-api | ||
if (args && args.constructor && args.constructor.name === 'CID') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better: if (args && cid.isCID(args))
@@ -32,6 +39,12 @@ module.exports = (send) => { | |||
}) | |||
}), | |||
stat: promisify((args, opts, callback) => { | |||
// TODO this needs to be adjusted with the new go-ipfs | |||
// http-api | |||
if (args && args.constructor && args.constructor.name === 'CID') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
// TODO this needs to be adjusted with the new go-ipfs | ||
// http-api | ||
|
||
if (typeof (cid) === 'function') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for parens
9a99d5a
to
4314815
Compare
86a6c25
to
813ab69
Compare
bcb89de
to
8030bf2
Compare
Ready for review :) @dignifiedquire @victorbjelkholm |
"socket.io": "^1.4.8", | ||
"socket.io-client": "^1.4.8", | ||
"socket.io": "^1.5.1", | ||
"socket.io-client": "^1.5.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where is socket.io actually used here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for the spawning of nodes when the requests come from the browser (IPFS Factory)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah okay, thanks
@haadcode important notice, with the reduction of bundle size + increased performance with the introduction of webcrypto usage, we had to move any hashing operation to become |
8030bf2
to
baa72d0
Compare
Got it. That's not ideal for the consumable API and we should, then, discuss and consider whether DAGNode is what should be returned. What are the use cases from consumer's perspective to have it as a DAGNode instead of, say, a plain Object? What prevents us to NOT return an Object, ie. what are the arguments to return a DAGNode? |
@haadcode now with CID's and support for multiple IPLD Formats, returning a plain object would mean that every IPLD format would need a 1:1 mapping to JSON. Note that in the Files API you still get a JSON, this only applies to the object API |
What does that mean? Can you elaborate a bit more? |
Absolutely! So, in order to yield JSON objects from the object (and very soon, dag API), we would need for an IPFS daemon (go, js, etc) to know how to serialize that object into JSON, which might be trivial[1] with protobuf or cbor, however it doesn't hold true to other IPLD formats (git, ethereum blocks, bitcoin blocks, etc) as this would require:
[1] - When I say trivial for the case of protobuf or cbor, it is actually not trivial at all, in fact, we are already 'hacking' the fact that JSON doesn't have any binary data types, while the dag-pb |
Are you saying that in the future go-ipfs HTTP API will return binary instead of JSON (current) for object.get? |
@haadcode it returns JSON, but the JSON serialization casts the Buffer to a String. In the 'near future' we need a way to hint which data types are being transferred, otherwise, it will be impossible to infer at all times, as I mention above, we could only do this for dag-pb because we know the "Data" field is a Buffer, always. |
Which can be added 'easily' by sending the serialized format, instead of a deserialized version, and deserializing at the client, enabling js-ipfs-api to return the right instance, always. |
Ok. We had a call with @diasdavid to talk about this and it is indeed a complex issue across the stack. We decided to move forwards and do two things:
|
on the new dag API, not the object API. Another thing that we discussed is to make the dagPB.DAGNode instance more funciton than OOP, where mutating state returns a new instance, so that we avoid having to call .multihash(cb) and .toJSON(cb) every time. This has been a long hitch and now finally we've gathered a strong motivation for it. |
For reference -> ipld/js-ipld-dag-pb#4 |
No description provided.